{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Make Two Arrays Equal by Reversing Subarrays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: canBeEqual"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #通过翻转子数组使两个数组相等"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个长度相同的整数数组&nbsp;<code>target</code>&nbsp;和&nbsp;<code>arr</code>&nbsp;。每一步中，你可以选择&nbsp;<code>arr</code>&nbsp;的任意 <strong>非空子数组</strong>&nbsp;并将它翻转。你可以执行此过程任意次。</p>\n",
    "\n",
    "<p><em>如果你能让 <code>arr</code>&nbsp;变得与 <code>target</code>&nbsp;相同，返回 True；否则，返回 False 。</em></p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>target = [1,2,3,4], arr = [2,4,1,3]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>你可以按照如下步骤使 arr 变成 target：\n",
    "1- 翻转子数组 [2,4,1] ，arr 变成 [1,4,2,3]\n",
    "2- 翻转子数组 [4,2] ，arr 变成 [1,2,4,3]\n",
    "3- 翻转子数组 [4,3] ，arr 变成 [1,2,3,4]\n",
    "上述方法并不是唯一的，还存在多种将 arr 变成 target 的方法。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>target = [7], arr = [7]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>arr 不需要做任何翻转已经与 target 相等。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>target = [3,7,9], arr = [3,7,11]\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>arr 没有数字 9 ，所以无论如何也无法变成 target 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>target.length == arr.length</code></li>\n",
    "\t<li><code>1 &lt;= target.length &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= target[i] &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= arr[i] &lt;= 1000</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [make-two-arrays-equal-by-reversing-subarrays](https://leetcode.cn/problems/make-two-arrays-equal-by-reversing-subarrays/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [make-two-arrays-equal-by-reversing-subarrays](https://leetcode.cn/problems/make-two-arrays-equal-by-reversing-subarrays/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,3,4]\\n[2,4,1,3]', '[7]\\n[7]', '[3,7,9]\\n[3,7,11]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        if sorted(arr) == sorted(target):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target=sorted(target)\n",
    "        arr=sorted(arr)\n",
    "        return target == arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        if target == arr:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        # arr.sort()\n",
    "        # target.sort()\n",
    "        # return arr == target\n",
    "        return sorted(target) == sorted(arr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        return target == arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)\n",
    "    \n",
    "    # 直接sort排序后比较即可"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target)==sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        target.sort()\n",
    "        if arr == target:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        conuter_target = Counter(target)\n",
    "        conuter_arr = Counter(arr)\n",
    "        return conuter_arr == conuter_target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: list[int], arr: list[int]) -> bool:\n",
    "        return sorted(target)==sorted(arr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target)==Counter(arr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        from collections import Counter\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        def reverse(i,j,L):\n",
    "            while i < j:\n",
    "                L[i], L[j] = L[j], L[i]\n",
    "                i += 1\n",
    "                j -= 1\n",
    "        n = len(target)\n",
    "        judge = True\n",
    "        for i in range(0,n):\n",
    "            index = -1  #在arr中寻找与当前匹配的首个位置\n",
    "            for j in range(i,n):\n",
    "                if arr[j] == target[i]:\n",
    "                    index = j\n",
    "                    break\n",
    "            if index == -1:\n",
    "                judge = False\n",
    "                break\n",
    "            reverse(i,index,arr)\n",
    "        return judge\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        return True if target == arr else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        n = len(target)\n",
    "        m = len(arr)\n",
    "        if n!=m:\n",
    "            return False\n",
    "        arr.sort()\n",
    "        target.sort()\n",
    "        if target==arr:\n",
    "            return True\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target)== sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target)==Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        return target==arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        for i in range(len(arr)):\n",
    "            if arr[i] != target[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        flag=True\n",
    "        for i in range(len(target)):            \n",
    "            if target[i]!=arr[i]:\n",
    "                flag=False\n",
    "        return flag\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: list[int], arr: list[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        n1=len(target)\n",
    "        n2=len(arr)\n",
    "        ret=0\n",
    "        if n1==n2:\n",
    "            for i in range(n1):\n",
    "                if target[i]==arr[i]:\n",
    "                    ret+=1\n",
    "        if ret==n1:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        len1=len(arr)\n",
    "        count=0\n",
    "        for i,j in zip(target,arr):\n",
    "            if i==j:\n",
    "                count+=1\n",
    "        if count==len1:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        return target==arr\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target)==sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target = sorted(target)\n",
    "        arr = sorted(arr)\n",
    "        return target == arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        flag=True\n",
    "        for i in range(len(target)):            \n",
    "            if target[i]!=arr[i]:\n",
    "                flag=False\n",
    "                break\n",
    "        return flag\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        target.sort()\n",
    "        return arr == target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        if all(target.count(i)==arr.count(i) for i in set(target)):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "      return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        dic1 = Counter(target)\n",
    "        dic2 = Counter(arr)\n",
    "        return dic1 == dic2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        from collections import Counter\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        return target == arr\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        if arr == target:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        target.sort()\n",
    "        for i in range(len(arr)):\n",
    "            if arr[i]!=target[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(arr) == Counter(target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return  Counter(target) == Counter(arr) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        counter=dict()\n",
    "        for i in range(len(arr)):\n",
    "            counter[arr[i]]=counter.get(arr[i],0)+1\n",
    "        for i in range(len(target)):\n",
    "            if target[i] in counter:\n",
    "                counter[target[i]]-=1\n",
    "        for key in counter:\n",
    "            if counter[key]!=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        target_len = len(target)\n",
    "        arr_len = len(arr)\n",
    "        if target_len != arr_len:\n",
    "            return False\n",
    "        target.sort()\n",
    "        arr.sort()\n",
    "        for i in range(target_len):\n",
    "            if target[i] != arr[i]:\n",
    "                return False\n",
    "        return True "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        d1=Counter(target)\n",
    "        d2=Counter(arr)\n",
    "        if len(d1)!=len(d2):\n",
    "            return False\n",
    "        for i in d1:\n",
    "            if i not in d2 or d1[i]!=d2[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target)==sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return sorted(target) == sorted(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        cnt0 = [0]*1001\n",
    "        cnt1 = [0]*1001\n",
    "\n",
    "        for i in range(len(target)):\n",
    "            cnt0[target[i]] += 1\n",
    "        for i in range(len(arr)):\n",
    "            cnt1[arr[i]] += 1\n",
    "    \n",
    "        for i in range(1000):\n",
    "            if cnt0[i] != cnt1[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        if all(target.count(i)==arr.count(i) for i in target):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:\n",
    "        return Counter(target) == Counter(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, target, arr) -> bool:\n",
    "        if len(target) != len(arr):\n",
    "            return False\n",
    "        a = set(target)\n",
    "        for i in a:\n",
    "            if target.count(i) == arr.count(i):\n",
    "                continue\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
